package edu.ynu.se.xiecheng.achitectureclass.common.utils;

import lombok.Data;

@Data
public class ResultMap {
    private Integer code;      // 状态码
    private String message;    // 提示信息
    private Object data;       // 数据

    // 成功静态方法
    public static ResultMap success() {
        ResultMap result = new ResultMap();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    public static ResultMap success(Object data) {
        ResultMap result = new ResultMap();
        result.setCode(200);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }

    public static ResultMap success(String message, Object data) {
        ResultMap result = new ResultMap();
        result.setCode(200);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    // 失败静态方法
    public static ResultMap error(String message) {
        ResultMap result = new ResultMap();
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    public static ResultMap error(Integer code, String message) {
        ResultMap result = new ResultMap();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
